import inherits from 'inherits';

import PropertiesActivator from 'bpmn-js-properties-panel/lib/PropertiesActivator';
// Require all properties you need from existing providers.
// In this case all available bpmn relevant properties without camunda extensions.
import processProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/ProcessProps';
import eventProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/EventProps';
import linkProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/LinkProps';
import documentationProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/DocumentationProps';
import idProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/IdProps';
import nameProps from 'bpmn-js-properties-panel/lib/provider/bpmn/parts/NameProps';
// 第一步引入说明  Require your custom property entries.
import spellProps from './parts/SpellProps';
import TitleProps from './parts/TitleProps';



// 2第二部创建函数 // 选项卡包含所有bpmn相关的属性

function createGeneralTabGroups(element, bpmnFactory, canvas, elementRegistry, translate) {

  var generalGroup = {
    id: 'general',
    label: 'General',
    entries: []
  };
  idProps(generalGroup, element, translate);
  nameProps(generalGroup, element, bpmnFactory, canvas, translate);
  processProps(generalGroup, element, translate);

  var detailsGroup = {
    id: 'details',
    label: 'Details',
    entries: []
  };
  linkProps(detailsGroup, element, translate);
  eventProps(detailsGroup, element, bpmnFactory, elementRegistry, translate);

  var documentationGroup = {
    id: 'documentation',
    label: 'Documentation',
    entries: []
  };

  documentationProps(documentationGroup, element, bpmnFactory, translate);
  return [
    generalGroup,
    detailsGroup,
    documentationGroup
  ];
}

// Create the custom magic tab
function createMagicTabGroups(element, translate) {
  // Create a group called "Black Magic".
  var blackMagicGroup = {
    id: 'black-magic',
    label: 'Black Magic',
    entries: []
  };

  // Add the spell props to the black magic group.
  spellProps(translate, blackMagicGroup, element);
  return [
    blackMagicGroup
  ];
}

// 权限选项卡
function createAuthorityTabGroups(element, translate) {
  var editAuthorityGroup = {
    id: 'edit-authority',
    label: '编辑权限',
    entries: []
  }

  // 每个属性都有自己的props方法
  TitleProps(translate, editAuthorityGroup, element);
  // OtherProps1(editAuthorityGroup, element);
  // OtherProps2(editAuthorityGroup, element);

  return [
    editAuthorityGroup
  ];
}



export default function MagicPropertiesProvider(eventBus, bpmnFactory, canvas, elementRegistry, translate) {
  PropertiesActivator.call(this, eventBus);
  this.getTabs = function (element) {
    // 第三步返回渲染
    return [
      {
        id: 'general',
        label: 'General',
        groups: createGeneralTabGroups(element, bpmnFactory, canvas, elementRegistry, translate)
      },
      // The "magic" tab
      {
        id: 'magic',
        label: 'Magic',
        groups: createMagicTabGroups(element, translate)
      },
      // The "权限" tab
      {
        id: 'authority',
        label: '权限',
        groups: createAuthorityTabGroups(element, translate)
      }
    ];
  };
}

inherits(MagicPropertiesProvider, PropertiesActivator);